package cn.just.student_mall.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2021-03-25 8:07
 * @Version 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取session中的用户id
        Integer uid = (Integer) request.getSession().getAttribute("uid");
        System.out.println(uid);
        if(uid == null){
            //重定向到登录界面
            response.sendRedirect("/web/login.html");
           //阻止放行
            return false;
        }
        //继续运行
        return true;
    }

}
